package lanqiao;

public class oneNumber {
    public int solution(int l,int r){
        int boundary = getHighestPosition(r^l);
        int top = 1 << boundary;
        int blew = 1 << (boundary-1);
        int heightNum = (r|(top-1)-(top-1));
        if ((heightNum+top-1) == r){
            return r;
        }
        return heightNum + blew - 1;
    }
    public int getHighestPosition(int num){
        int res = 0;
        while (num!=0){
            res++;
            num = (num>>1);
        }
        return res;
    }
}
